//
//  HMAddCaseTwoCell.m
//  仿真开发
//
//  Created by B.HOPE on 2017/3/24.
//  Copyright © 2017年 B.HOPE. All rights reserved.
//

#import "HMAddCaseTwoCell.h"
#import <Masonry.h>

@interface HMAddCaseTwoCell ()

@property (nonatomic, strong) UIButton *caseBtn1;

@property (nonatomic, strong) UIButton *caseBtn2;

@property (nonatomic, strong) UIButton *caseBtn3;

@end

@implementation HMAddCaseTwoCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI
{
    UILabel *describe = [[UILabel alloc] init];
    describe.text = @"疾病描述";
    describe.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:describe];
    [describe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
    }];
    
    UIButton *imgBtn = [[UIButton alloc] init];
    [imgBtn setImage:[UIImage imageNamed:@"add"] forState:UIControlStateNormal];
    [self.contentView addSubview:imgBtn];
    [imgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(describe);
        make.right.offset(-10);
    }];
    [imgBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *titleBtn = [[UIButton alloc] init];
    [titleBtn setTitle:@"添加病症描述书签" forState:UIControlStateNormal];
    titleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [titleBtn setTitleColor:[UIColor colorWithRed:77/255.0 green:194/255.0 blue:156/255.0 alpha:1] forState:UIControlStateNormal];
    [self.contentView addSubview:titleBtn];
    [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(describe);
        make.right.equalTo(imgBtn.mas_left).offset(-5);
    }];
    [titleBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    _caseBtn1 = [[UIButton alloc] init];
    [_caseBtn1 setTitle:@"高血压" forState:UIControlStateNormal];
    [_caseBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _caseBtn1.backgroundColor = [UIColor redColor];
    _caseBtn1.layer.cornerRadius = 5;
    _caseBtn1.layer.masksToBounds = YES;
    _caseBtn1.hidden = YES;
    [self.contentView addSubview:_caseBtn1];
    [_caseBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(describe.mas_bottom).offset(10);
        make.left.offset(10);
        make.size.mas_offset(CGSizeMake(60, 50));
    }];
    
    _caseBtn2 = [[UIButton alloc] init];
    [_caseBtn2 setTitle:@"高血糖" forState:UIControlStateNormal];
    [_caseBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _caseBtn2.backgroundColor = [UIColor redColor];
    _caseBtn2.layer.cornerRadius = 5;
    _caseBtn2.layer.masksToBounds = YES;
    _caseBtn2.hidden = YES;
    [self.contentView addSubview:_caseBtn2];
    [_caseBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_caseBtn1);
        make.left.equalTo(_caseBtn1.mas_right).offset(10);
        make.size.mas_offset(CGSizeMake(60, 50));
    }];
    
    _caseBtn3 = [[UIButton alloc] init];
    [_caseBtn3 setTitle:@"高血脂" forState:UIControlStateNormal];
    [_caseBtn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _caseBtn3.backgroundColor = [UIColor redColor];
    _caseBtn3.layer.cornerRadius = 5;
    _caseBtn3.layer.masksToBounds = YES;
    _caseBtn3.hidden = YES;
    [self.contentView addSubview:_caseBtn3];
    [_caseBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_caseBtn2);
        make.left.equalTo(_caseBtn2.mas_right).offset(10);
        make.size.mas_offset(CGSizeMake(60, 50));
    }];
    
    UITextField *text = [[UITextField alloc] init];
    text.placeholder = @"填写附加信息";
    text.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_caseBtn1.mas_bottom).offset(10);
        make.left.offset(10);
    }];
    
    UILabel *footLabel = [[UILabel alloc] init];
    footLabel.text = @"选择图片";
    footLabel.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:footLabel];
    [footLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(text.mas_bottom).offset(30);
        make.left.equalTo(text);
        make.right.bottom.offset(-10);
    }];
}

- (void)setArrayModel:(NSArray *)arrayModel
{
    _arrayModel = arrayModel;
    
    if (_arrayModel == nil)
    {
        return;
    }
    
    if (_arrayModel.count == 1)
    {
        _caseBtn1.hidden = NO;
        [_caseBtn1 setTitle:_arrayModel[0] forState:UIControlStateNormal];
    } else if (_arrayModel.count == 2) {
        _caseBtn1.hidden = NO;
        [_caseBtn1 setTitle:_arrayModel[0] forState:UIControlStateNormal];
        _caseBtn2.hidden = NO;
        [_caseBtn2 setTitle:_arrayModel[1] forState:UIControlStateNormal];
    } else if (_arrayModel.count == 3) {
        _caseBtn1.hidden = NO;
        [_caseBtn1 setTitle:_arrayModel[0] forState:UIControlStateNormal];
        _caseBtn2.hidden = NO;
        [_caseBtn2 setTitle:_arrayModel[1] forState:UIControlStateNormal];
        _caseBtn3.hidden = NO;
        [_caseBtn3 setTitle:_arrayModel[2] forState:UIControlStateNormal];
    }
}

- (void)clickBtn:(UIButton *)sender
{
    [self.delegate addCaseTwo:self Title:sender];
}

@end
